package com.yinhe.music.yhmusic.video;

import android.graphics.Color;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yinhe.music.common.GlideHelper.GlideHelper;
import com.yinhe.music.common.utils.KeywordUtil;
import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.model.MvsInfo;

/**
 * Created by hasee on 2017/8/15.
 */

public class MvAdapter extends BaseMultiItemQuickAdapter<MvsInfo, BaseViewHolder> {
    private String key;

    public MvAdapter(String key) {
        super(null);
        addItemType(MvsInfo.MORE, R.layout.fragment_mv_item);
        addItemType(MvsInfo.SINGER_DETAIL, R.layout.fav_mv_item);
        addItemType(MvsInfo.FAV, R.layout.fav_mv_item);
        this.key = key;
    }

    public void setSearchKey(String key) {
        this.key = key;
    }
    @Override
    protected void convert(BaseViewHolder helper, MvsInfo item) {
        int max = 10000;
        helper.setText(R.id.mv_name, item.getMovieName())
                .setText(R.id.mv_artist_name, item.getSingerName());
        ImageView image = helper.getView(R.id.mv_pic);

        if (key != null && key.equals("collection")){
            helper.setImageResource(R.id.mv_collect, R.drawable.ic_heart_red);
        }else {
            if (item.getCollectStatus() == 0) {
                helper.setImageResource(R.id.mv_collect, R.drawable.ic_heart_grey);
            } else {
                helper.setImageResource(R.id.mv_collect, R.drawable.ic_heart_red);
            }
        }

        helper.addOnClickListener(R.id.mv_collect);
        helper.addOnClickListener(R.id.mv_share);

        if (helper.getItemViewType() == MvsInfo.MORE){
            if (item.getPlayNum() > max) {
                helper.setText(R.id.mv_listen_count, item.getPlayNum() / max + "万");
            } else {
                helper.setText(R.id.mv_listen_count, String.valueOf(item.getPlayNum()));
            }
            helper.addOnClickListener(R.id.mv_comment);
        }

        GlideHelper.setImageResource(image, item.getImage(), R.drawable.default_cover);

        if (key != null) {
            helper.setText(R.id.mv_name, KeywordUtil.matcherSearchTitle(Color.parseColor("#1d89ff"),item.getMovieName(),key));
            helper.setText(R.id.mv_artist_name, KeywordUtil.matcherSearchTitle(Color.parseColor("#1d89ff"),item.getSingerName(),key));
        }
    }
}
